Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var assert = require('chai').assert, |
||
4 | describe('Identifiers', function(){ |
||
5 | |||
6 | it('Create plain', function(){ |
||
7 | var newIdent = new GedcomX.Identifiers(), |
||
8 | ident = GedcomX.Identifiers(); |
||
9 | assert.instanceOf(newIdent, GedcomX.Identifiers, 'An instance of Identifiers is not returned when calling the constructor with new.'); |
||
10 | assert.instanceOf(ident, GedcomX.Identifiers, 'An instance of Identifiers is not returned when calling the constructor without new.'); |
||
11 | }); |
||
12 | |||
13 | it('Create with JSON', function(){ |
||
14 | var ident = GedcomX.Identifiers({ |
||
15 | $: [ 'value_with_no_type' ], |
||
16 | list: [ 'one', 'two' ], |
||
17 | collapse: 'single_value' |
||
18 | }); |
||
19 | assert.deepEqual(ident.getValues(), [ 'value_with_no_type' ]); |
||
20 | assert.deepEqual(ident.getValues('list'), [ 'one', 'two' ]); |
||
21 | assert.deepEqual(ident.getValues('collapse'), [ 'single_value' ]); |
||
22 | }); |
||
23 | |||
24 | it('Build', function(){ |
||
25 | var ident = GedcomX.Identifiers(); |
||
26 | ident.addValue('value_with_no_type'); |
||
27 | ident.addValue('one', 'list'); |
||
28 | ident.addValue('two', 'list'); |
||
29 | ident.addValue('single_value', 'collapse'); |
||
30 | assert.deepEqual(ident.getValues(), [ 'value_with_no_type' ]); |
||
31 | assert.deepEqual(ident.getValues('list'), [ 'one', 'two' ]); |
||
32 | assert.deepEqual(ident.getValues('collapse'), [ 'single_value' ]); |
||
33 | }); |
||
34 | |||
35 | it('toJSON() and single string collapsing', function(){ |
||
36 | var ident = GedcomX.Identifiers({ |
||
37 | $: [ 'value_with_no_type' ], |
||
38 | list: [ 'one', 'two' ], |
||
39 | collapse: 'single_value' |
||
40 | }); |
||
41 | assert.deepEqual(ident.toJSON(), { |
||
42 | $: [ 'value_with_no_type' ], |
||
43 | list: [ 'one', 'two' ], |
||
44 | collapse: [ 'single_value' ] |
||
45 | }); |
||
46 | }); |
||
47 | |||
48 | it('constructor does not copy instances', function(){ |
||
49 | var obj1 = GedcomX.Identifiers(); |
||
50 | var obj2 = GedcomX.Identifiers(obj1); |
||
51 | assert.strictEqual(obj1, obj2); |
||
52 | }); |
||
53 | |||
54 | }); |